//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Files.Components;

namespace CommunityServer.ControlPanel.Files
{
	/// <summary>
	/// Summary description for UserDownloadCsv.
	/// </summary>
	public class UserDownloadCsv : BaseFilesPage
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			UserDownloadSet uds = CommunityServer.Files.UserDownloads.GetUserDownloads(Int32.Parse(Request.QueryString["pid"]), DateTime.Parse(Request.QueryString["brd"]), DateTime.Parse(Request.QueryString["erd"]), 0, int.MaxValue - 1); 
			Response.Clear();
			Response.Cache.SetLastModified(DateTime.Now);
			Response.ContentType = "text/csv; name=\"DownloadHistory.csv\"";
			Response.AddHeader("Content-disposition", "inline; filename=\"DownloadHistory.csv\"");

			foreach (UserDownload ud in uds.UserDownloads)
			{
				Response.Write(String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"\n", 
					ud.User.Username.Replace("\"", "\"\""), 
					ud.User.DisplayName.Replace("\"", "\"\""), 
					ud.User.Email.Replace("\"", "\"\""), 
					ud.TotalDownloads.ToString(),
					(ud.LatestDownloadDate.ToShortDateString() + " " + ud.LatestDownloadDate.ToShortTimeString()).Replace("\"", "\"\"")));
			}

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
